package com.atguigui.leetcode;

/**
 * 388.文件的最长绝对路径
 * Project: leetcode
 * Package: com.atguigui.leetcode
 * Version: 1.0
 * <p>
 * Created by  wangjiaxin  on 2022/4/20 23:22
 */
public class P388LongestAbsoluteFilePath {
    public static void main(String[] args) {
        Solution solution = new P388LongestAbsoluteFilePath().new Solution();
        // TO TEST
    }

    //leetcode submit region begin(Prohibit modification and deletion)
    class Solution {
        public int lengthLongestPath(String input) {

            int ans = 0;
            int n = input.length();

            int[] depth_length_map = new int[n + 1];

            // "dir\n\tsubdir1\n\tsubdir2\n\t\tfile.ext"
            for (String line : input.split("\n")) {
                //深度，dir的深度为0
                int depth = line.split("\t").length - 1;

                if (depth > 0) {
                    depth_length_map[depth] = depth_length_map[depth - 1] + line.length() - depth;
                } else {
                    depth_length_map[depth] = line.length() - depth;
                }

                if (line.contains(".")) {
                    ans = Math.max(ans, depth_length_map[depth] + depth);
                }

            }


            return ans;
        }
    }
}
